package com.wc.alorithm_blue_bridge.线段树.最大公约数;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/3/17 22:43
 * @description
 * https://www.lanqiao.cn/courses/46292/learning/?id=3440217&compatibility=false
 */
public class Main {
    /**
     * 思路：
     * 线段树维护区间 gcd
     * 二分查找可以最小区间生成 1 的长度, 如果长度为 1, 说明数组中存在 1, 那答案就是 n - cnt, cnt为 1 的个数
     * 如果区间长度 > 1, 假设是 L, 那就用 L - 1步生成 1, 然后用这个 1 同化所有的其他数, L - 1 + n - 1
     * 树顶不是 1, 说明他们生成不了全是 1的数组
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010, M = N << 2;
    static int[] t = new int[M], a = new int[N];
    static int n;

    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 1; i <= n; i++) a[i] = sc.nextInt();
        build(1, 1, n);
        if (t[1] != 1) out.println(-1);
        else {
            int l = 1, r = n;
            while (l < r) {
                int mid = l + r >> 1;
                if (check(mid)) r = mid;
                else l = mid + 1;
            }

            if (r == 1) {
                int cnt = 0;
                for (int i = 1; i <= n; i++) {
                    if (a[i] == 1) cnt++;
                }
                out.println(n - cnt);
            } else out.println(r - 1 + n - 1);
        }
        out.flush();
    }

    static boolean check(int len) {
        for (int i = 1; i <= n - len + 1; i++) {
            if (query(1, 1, n, i, i + len - 1) == 1) return true;
        }
        return false;
    }

    static int query(int u, int l, int r, int ql, int qr) {
        if (l == ql && r == qr) {
            return t[u];
        }
        int mid = l + r >> 1;
        if (qr <= mid) return query(u << 1, l, mid, ql, qr);
        if (ql > mid) return query(u << 1 | 1, mid + 1, r, ql, qr);
        int L = query(u << 1, l, mid, ql, mid);
        int R = query(u << 1 | 1, mid + 1, r, mid + 1, qr);
        return gcd(L, R);
    }

    static void build(int u, int l, int r) {
        if (l == r) {
            t[u] = a[l];
            return;
        }
        int mid = l + r >> 1;
        build(u << 1, l, mid);
        build(u << 1 | 1, mid + 1, r);
        pushUp(u);
    }

    static void pushUp(int u) {
        t[u] = gcd(t[u << 1], t[u << 1 | 1]);
    }


    static int gcd(int a, int b) {
        return b > 0 ? gcd(b, a % b) : a;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

